package com.seth.myapplication.surface;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.seth.myapplication.MainActivity;
import com.seth.myapplication.R;

/**
 * Created by Seth on 2017/10/24.
 */

public class ReleaseSuccess extends Fragment {

    private Button continueBtn;
    private Button completeBtn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_release_successful, container, false);

        initView(view);

        initEvent();


        return view;

    }

    private void initEvent() {
        continueBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

               // getActivity().onBackPressed();
                MainActivity parentActivity = (MainActivity)getActivity();
                MainActivity.setContentFragment(ReleaseSuccess.this);
                parentActivity.ToSecondPage(getView());
            }
        });

        completeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity parentActivity = (MainActivity)getActivity();
                MainActivity.setContentFragment(ReleaseSuccess.this);
                parentActivity.ToFirstPage(getView());
            }
        });

    }

    private void initView(View view) {
        continueBtn = (Button) view.findViewById(R.id.continue_release_btn);
        completeBtn = (Button) view.findViewById(R.id.complete_release_btn);
    }
//    public void setFragment(Fragment fragment) {
//
//        FragmentTransaction transaction = getFragmentManager().beginTransaction();
////        transaction.replace(R.id.fragment_container,fragment);
////       //transaction.hide(fragment1).add(R.id.activity_login, fragment);
////        MainActivity.setContentFragment(fragment);
////        transaction.addToBackStack(null);
////        transaction.commit();
//
//        if(!fragment.isAdded()){    //如果当前fragment为被添加，则添加到Fragment管理器中
//            transaction.hide(MainActivity.getContentFragment()).add(R.id.fragment_container, fragment).commit();
//        }else{
//            transaction.hide(MainActivity.getContentFragment()).show(fragment).commit();
//        }
//        MainActivity.setContentFragment(fragment);
//    }
}
